/**
 * Created by admin on 2018/1/24.
 */
layui.config({
    base : "../js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    //创建一个编辑器
    var editIndex = layedit.build('loss_content');
    var addLossArray = [],addLoss;
    form.on("submit(addLoss)",function(data){
        //是否添加过信息
        if(window.sessionStorage.getItem("addLoss")){
            addLossArray = JSON.parse(window.sessionStorage.getItem("addLoss"));
        }


        addLoss = '{"accidentId":"'+$(".accidentId").val()+'",';  //事故编号
        addLoss += '"accidentName":"'+$(".accidentName").val()+'",'; //事故名称
        addLoss += '"lossLevel":"'+$(".lossLevel option").eq($(".lossLevel").val()).text()+'",'; //损失等级
        addLoss += '"number":"'+$(".number").val()+'",'; //人员伤亡
        addLoss += '"money":"'+$(".money").val()+'",'; //经济损失
        addLoss += '"environment":"'+$(".environment").val()+'"}'; //环境损害
        addLossArray.unshift(JSON.parse(addLoss));
        window.sessionStorage.setItem("addLoss",JSON.stringify(addLossArray));
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("文章添加成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },2000);
        return false;
    })

})